package com.ruoyi.biz.api.controller;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.biz.api.context.ApiContext;
import com.ruoyi.biz.domain.*;
import com.ruoyi.biz.dto.BaseDTO;
import com.ruoyi.biz.dto.EquipmentInfoDTO;
import com.ruoyi.biz.param.EquipmentInfoParam;
import com.ruoyi.biz.service.*;
import com.ruoyi.biz.vo.AdminVo;
import com.ruoyi.biz.vo.EquipmentVo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.ApiResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2020-11-30
 */
@RestController
@RequestMapping("/api/equipment")
@Api(tags = "设备接口")
public class EquipmentInfoApiController extends BaseController
{
    @Resource
    private IEquipmentInfoService equipmentInfoService;

    @ApiOperation("首页设备信息")
    @GetMapping("/info")
    public ApiResult<List<EquipmentInfoDTO>> infoList(){
        EquipmentInfo equipmentInfo = new EquipmentInfo();
        equipmentInfo.setCustomerId(ApiContext.getCurrentUserId());
        List<EquipmentInfoDTO> list = equipmentInfoService.selectInfoList(equipmentInfo);
        return ApiResult.success(list);
    }

    @ApiOperation("设备列表")
    @GetMapping("/list")
    public ApiResult<PageInfo<EquipmentInfoDTO>> list(BaseDTO dto){
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        EquipmentInfo equipmentInfo = new EquipmentInfo();
        equipmentInfo.setCustomerId(ApiContext.getCurrentUserId());
        List<EquipmentInfoDTO> list = equipmentInfoService.selectEquipmentInfoDTOList(equipmentInfo);
        return ApiResult.success(new PageInfo<>(list));
    }

    @ApiOperation("新增设备")
    @PostMapping
    public ApiResult add(@RequestBody EquipmentInfoParam param){
        EquipmentInfo equipmentInfo = BeanUtil.copyProperties(param, EquipmentInfo.class);
        equipmentInfo.setCustomerId(ApiContext.getCurrentUserId());
        return ApiResult.toAjax(equipmentInfoService.insertEquipmentInfo(equipmentInfo));
    }


    @ApiOperation("修改设备")
    @PutMapping
    public ApiResult update(@RequestBody EquipmentInfoParam param){
        EquipmentInfo equipmentInfo = BeanUtil.copyProperties(param, EquipmentInfo.class);
        return ApiResult.toAjax(equipmentInfoService.updateEquipmentInfo(equipmentInfo));
    }

    @ApiOperation("删除设备")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "equipmentId",value = "设备Id",dataType = "Long",example = "1",required = true),
    })
    @DeleteMapping("/{equipmentId}")
    public ApiResult delete(@PathVariable Long equipmentId){
        return ApiResult.toAjax(equipmentInfoService.deleteEquipmentInfoById(equipmentId));
    }
}
